const _ = require('lodash');
foodController.$inject = [
    '$scope',
    'foodService', 
    '$location']

function foodController($scope, foodService, $location){
    var fc = this;

    $scope.foods = {};
    $scope.searchInput = '';
    let merchantId = sessionStorage.getItem("merchantId");

    foodService.getFoodsByMerchantId(merchantId, (err, result) => {
        console.log("要查找的id为： "+merchantId);
        $scope.foods = result;
        _.forEach($scope.foods, (item) => {
            item.num = 1;
        })
    });

    fc.getFoodsByType = function(type){
        console.log("食品类型 "+type);
        foodService.getFoodsByType(type, merchantId, (err, result) => {
            $scope.foods = result;
            _.forEach($scope.foods, (item) => {
                item.num = 1;
            })
        })
    };

    fc.getAllFoods = function(){
        console.log("Get all");
        foodService.getFoodsByMerchantId(merchantId, (err, result) => {
            $scope.foods = result;
            _.forEach($scope.foods, (item) => {
                item.num = 1;
            })
        });
    }

    fc.searchFoodsByKewWordInMerchantStore = function(){
        let keyword = $scope.searchInput;
        let test = ['aaa', 'abc', 'abddc', 'addabc', 'abasgdc'];
        $scope.candidatedFoodList = test;
        // _.forEach(test, (item) => {
            
        // })
        console.log(keyword);
    //     foodService.getFoodsByKeyWordAndMerchantId(keyword, merchantId, (err, result) => {

    //    })
    }

}

module.exports = foodController;